<?php

  /**
   * FilterAction
   *
   * Действие для фильтрации отдаваемого контента
   */

  class FilterAction extends AjaxAction
  {
    /**
     * выполнить действие
     *
     * @return void
     * @access public
     */
    public function run()
    {
      /** @var $app WebApplication */
      $app = $this->getController()->getApp();

      is_array($this->data) or ($this->data = array());

      if (($f = $app->getParam("f")) && ($v = $app->getParam("v")))
        switch ($f)
        {
          case "date" :
            $this->data["filter"] = "`date`='$v'";
            break;
          case "month":
            list($year, $month) = explode("-", $v, 2);
            $this->data["filter"] = "year(`date`)='$year' and month(`date`)='$month'";
            break;
          case "year":
            $this->data["filter"] = "year(`date`)='$v'";
            break;
          case "user" :
            $this->data["filter"] = "`user_id`='$v'";
            break;
        }

      parent::run();
    }
  }

?>